<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI视频生成工具</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .nav-tabs {
            display: flex;
            border-bottom: 1px solid #ddd;
            margin-bottom: 20px;
        }
        .nav-tab {
            padding: 10px 20px;
            cursor: pointer;
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            border-bottom: none;
            border-radius: 5px 5px 0 0;
            margin-right: 5px;
        }
        .nav-tab.active {
            background-color: white;
            border-bottom: 1px solid white;
            margin-bottom: -1px;
        }
        .tab-content {
            display: none;
        }
        .tab-content.active {
            display: block;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            border: none;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #0056b3;
        }
        .btn-secondary {
            background-color: #6c757d;
        }
        .btn-secondary:hover {
            background-color: #5a6268;
        }
        .message {
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
        }
        .message.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .message.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .task-list {
            margin-top: 20px;
        }
        .task-item {
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 10px;
            background-color: #f8f9fa;
        }
        .task-item a {
            color: #007bff;
            text-decoration: none;
        }
        .task-item a:hover {
            text-decoration: underline;
        }
        .nav-link {
            display: inline-block;
            margin: 10px 5px;
            color: #007bff;
            text-decoration: none;
            padding: 10px 15px;
            border: 1px solid #007bff;
            border-radius: 5px;
        }
        .nav-link:hover {
            background-color: #007bff;
            color: white;
        }
        .task-list {
            margin-top: 20px;
        }
        .task-item {
            padding: 10px;
            border: 1px solid #ddd;
            margin-bottom: 10px;
            border-radius: 4px;
            background-color: #f8f9fa;
        }
        .task-title {
            font-weight: bold;
            color: #333;
        }
        .task-status {
            float: right;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
        }
        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }
        .status-running {
            background-color: #cce5ff;
            color: #004085;
        }
        .status-completed {
            background-color: #d4edda;
            color: #155724;
        }
        .status-failed {
            background-color: #f8d7da;
            color: #721c24;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>AI视频生成工具</h1>
        
        <div style="text-align: center; margin: 20px 0;">
            <a href="/t2v" class="nav-link">文本生成视频</a>
            <a href="/female-portrait-video" class="nav-link">女性肖像视频</a>
            <a href="/image-edit" class="nav-link">图片编辑</a>
            <a href="/local-file" class="nav-link">本地文件处理</a>
            <a href="/excel-processor" class="nav-link">Excel批量处理</a>
            <a href="/keyword-configs" class="nav-link">关键词配置</a>
            <a href="/sora2" class="nav-link">Sora2视频生成</a>
            <a href="/batch-lipsync" class="nav-link">对口型视频生成</a>
        </div>
        
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="message {{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        
        <div class="task-list">
            <h2>最近任务</h2>
            <div id="taskList">
                <!-- 任务列表将通过JavaScript动态加载 -->
            </div>
        </div>
    </div>

    <script>
        // 页面加载时获取任务列表
        window.onload = function() {
            loadTaskList();
        };
        
        function loadTaskList() {
            fetch('/tasks')
                .then(response => response.text())
                .then(html => {
                    document.getElementById('taskList').innerHTML = html;
                })
                .catch(error => {
                    console.error('Error loading task list:', error);
                });
        }
        
        function submitForm() {
            const formData = new FormData();
            formData.append('images_dir', document.getElementById('images_dir').value);
            formData.append('audios_dir', document.getElementById('audios_dir').value);
            formData.append('output_dir', document.getElementById('output_dir').value);
            formData.append('generation_type', document.getElementById('generation_type').value);
            
            fetch('/generate', {
                method: 'POST',
                body: formData
            })
            .then(response => response.text())
            .then(html => {
                // 重新加载页面以显示flash消息
                location.reload();
            })
            .catch(error => {
                alert('提交失败: ' + error.message);
            });
        }
    </script>
</body>
</html>